using System;

namespace Battle.TimelineLog
{
    /// <summary>
    /// hp或mp或tp等数值的抽象类
    /// </summary>
    public abstract class BasePoint
    {
        public int Value { get; private set; }
        public int MaxValue { get; private set; }

        public BasePoint() { }
        public BasePoint(int max)
        {
            SetMaxValue(max);
            Reset();
        }
        public BasePoint(int crt, int max)
        {
            Value = crt;
            SetMaxValue(max);
        }

        public void Reset()
        {
            Value = MaxValue;
        }

        public void SetMaxValue(int value, bool resetCrtHp = false)
        {
            MaxValue = value;
            if (resetCrtHp) Reset();
        }

        /// <summary>
        /// 减少
        /// </summary>
        /// <param name="value"></param>
        public void Minus(int value)
        {
            Value = Math.Max(0, Value - value);
        }

        /// <summary>
        /// 增加
        /// </summary>
        /// <param name="value"></param>
        public virtual void Add(int value)
        {
            Value = Math.Min(MaxValue, Value + value);
        }

        /// <summary>
        /// 获取当前x量和最大x量的百分比
        /// </summary>
        /// <returns></returns>
        public float Percent()
        {
            return (float)Value / MaxValue;
        }

        /// <summary>
        /// 获取当前x量的百分比数值
        /// </summary>
        /// <param name="pct"></param>
        /// <returns></returns>
        public int PercentHealth(int pct)
        {
            return (int)(Value * (pct / 100f));
        }

        /// <summary>
        /// 获取最大x量的百分比数值
        /// </summary>
        /// <param name="pct"></param>
        /// <returns></returns>
        public int PercentMaxHealth(int pct)
        {
            return (int)(MaxValue * (pct / 100f));
        }

        /// <summary>
        /// 是否满x
        /// </summary>
        /// <returns></returns>
        public bool IsFull()
        {
            return Value == MaxValue;
        }
    }
}